package Element.Geom;

import java.awt.*;
import java.awt.geom.*;

import DistSys.*;
import Element.*;

public class LineGeom extends TwoNodeElemGeom implements Cloneable {

    boolean isCable;
    //public boolean isAutoValue;

    public LineGeom() {
        super();
        isCable=false;
        //isAutoValue = false;
    }

    //init from drawing
    public void initFromScreen(String n, boolean b) {
        init(n);
        isCable = b;
    }

    //init from DB ; this is an overloadded method!!!
    public void initFromDB(String n, String desc, int r, int LTC,
                           boolean sn, boolean sd, int[][] si, Point pt,
                           Point pt2, boolean b) {
        //super==>TwoNodeElemGeom
        super.initFromDB(n, desc, r, LTC, sn, sd, si, pt, pt2);
        isCable = b;
    }

    //AbsLineGeom 's own methods
    public boolean getIsCable(){ return isCable; }
    public void    setIsCable(boolean b){ isCable=b; }

    public void calcFrame(){} // do nothing; frame is N/A to line

    public void toggle(){
        isCable = (!isCable);
    }


    //**********************************************
    //overridden methods
    //**********************************************

    //not used for checking connectivity which needs stored values
    public boolean coverPoint( int x, int y, int snap){
        double k1,k2;

        if( isStartPoint(x,y, snap) == true ) return true;
        if( isEndPoint(x,y, snap) == true) return true;

        Line2D.Float ln = new Line2D.Float(x1, y1, x2, y2);

        if( snap ==0) return ln.contains(x,y);
        else return ln.intersects(x-snap,y-snap, 2*snap, 2*snap);
    }//end of coverPoint()

    public void incRotate(){} // do nothing; rotate is N/A to line

    public Object clone(){
        LineGeom created = new LineGeom();  // all ref. in created has been instantiated
                                         // such as frame, conn1,conn2, childList

        this.copyTo( created);// copy AbsElemGeom attributes to created

        //LineGeom's own data
        created.isCable = this.isCable;
        //created.isAutoValue = this.isAutoValue;

        return created;
    }
}